import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";

Vue.use(VueRouter);

const routes = [
    {
        path: "/",
        name: "Home",
        component: Home,
    },
    {
        path: "/quan",
        name: "quan",
        component: () => import("../views/quan"),
    },
    {
        path: "/guan",
        name: "guan",
        component: () => import("../views/guan"),
    },
    {
        path: "/shoplist",
        name: "shoplist",
        component: () => import("../views/shoplist"),
    },
    {
        path: "/shou",
        name: "shou",
        component: () => import("../views/shou"),
    },
    {
        path: "/ding",
        name: "ding",
        component: () => import("../views/ding"),
    },
    {
        path: "/xiang",
        name: "xiang",
        component: () => import("../views/xiang"),
    },
    {
        path: "/login",
        name: "login",
        component: () => import("../views/login"),
    },
];

const router = new VueRouter({
    routes,
});
router.beforeEach((to, from, next) => {
    if (localStorage.getItem("token")) {
        next();
    } else {
        if (to.path != "/shoplist" && to.path != "/shou") {
            next();
        } else {
            next("/login");
        }
    }
});

export default router;
